package com.hnevc.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;

class MyListener implements ActionListener{
	@Override
	public void actionPerformed(ActionEvent e) {
		System.out.println("按钮被点击了"+((JButton)e.getSource()).getText());
	}
}
public class ActionListenerDemo  extends JFrame{
	JButton button;
	public ActionListenerDemo(){
		button = new JButton("按钮");
		MyListener listener = new MyListener();
		button.addActionListener(listener);
		this.add(button);
		this.setLocation(200, 200);
		this.setSize(200,200);
		this.setVisible(true);
	}
	public static void main(String[] args) {
		new ActionListenerDemo();
	}
}
